package router

import (
	"gin-learn-notes/controller"
	"gin-learn-notes/middleware"

	"github.com/gin-gonic/gin"
)

func InitRouter() *gin.Engine {
	// 创建默认的 Gin 引擎
	r := gin.Default()

	// 定义一个基本的路由
	r.GET("/ping", controller.Ping)
	r.POST("/register", controller.Register)
	r.GET("/hello", controller.HelloHandler) // 支持访问 /hello?name=Gin
	r.GET("/user/:id", func(c *gin.Context) {
		id := c.Param("id")
		c.JSON(200, gin.H{"user_id": id})
	})

	r.POST("/info", controller.GetUserInfo)
	r.POST("/save", controller.UpdateUser)
	r.POST("/delete", controller.DeleteUser)
	r.POST("/list", controller.UserList)

	r.POST("/login", controller.Login)

	// 需要登录的接口分组
	auth := r.Group("/api")
	auth.Use(middleware.JWTAuthMiddleware())
	{
		// 新增用户信息获取接口
		auth.POST("/profile", controller.GetUserProfile)
	}

	return r
}
